package com.zx.sys.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.common.utils.PageUtils;
import com.zx.common.utils.Query;
import com.zx.sys.cms.dao.CmsContentDao;
import com.zx.sys.cms.entity.CmsContentEntity;
import com.zx.sys.cms.service.CmsContentService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("cmsContentService")
public class CmsContentServiceImpl extends ServiceImpl<CmsContentDao, CmsContentEntity> implements CmsContentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CmsContentEntity> page = new Query<CmsContentEntity>().getPage(params);
        page.setRecords(baseMapper.selectListPage(page,params));
        return new PageUtils(page);
    }

    public PageUtils queryPageByChannel(Map<String, Object> params) {
        Integer chnlId = Integer.parseInt((String)params.get("channelId"));
        IPage<CmsContentEntity> page = this.page(
                new Query<CmsContentEntity>().getPage(params),
                new QueryWrapper<CmsContentEntity>()
                .eq("channel_id",chnlId)
                .eq("status", 1)
                .orderByAsc("top_level")
                .orderByDesc("create_time")
        );

        return new PageUtils(page);
    }


    @Override
    public List<CmsContentEntity> selectTopList(Map<String, Object> params) {
        return baseMapper.selectTopList(params);
    }
}
